<?php
namespace Home\Controller;


class DialyController extends AdminController{

	private $_dialy;//操作日志表对象
	private $_user;//操作用户表日志
	private $_comment;//评论表
	public function __construct(){
		parent::__construct();
		$this->_dialy=M('diary');
		$this->_user=M('user');
		$this->_comment=M('comment');
	}
	//先看自己的说说，在看好友的说说（好难）
	public function index(){
		$id=$_SESSION['love_user']['id'];//模拟当前登录session中的用户id	
		//遍历好友的
		// $dataFriend=$this->_user->field('love_diary.id as wid,name,love_diary.utime as dutime,uid,content')->join("join love_diary on love_user.id=love_diary.uid and love_user.id in()")->order('love_diary.utime desc')->select();


		//遍历自己的
	    $dataList=$this->_user->field('love_diary.id as wid,name,love_diary.utime as dutime,uid,content')->join("join love_diary on love_user.id=love_diary.uid and love_user.id={$id}")->order('love_diary.utime desc')->select();
        // $dataPcont=$this->_comment->
        
    //     // $sql="select * from love_comment,"
	   //      dump($this->_user->getLastSql());
		  // //   // var_dump($dataList);exit;
		  // //   dump($dataList);
		  //  foreach($dataList as $v){
    //    		$vwid=$v['wid']; 	//文章id
    //   		$vuid=$v['uid'];	//用户id
		  // }
		  dump($dataList);
		$this->assign('list',$dataList);
		$this->display();
	}
	public function addContent(){

		$uid=$_SESSION['love_user']['id'];       //模拟session中的用户id
		$utime=time();  //获取当前时间
		$content=htmlspecialchars(I('contentD'));
	    $tyData=array('uid'=>$uid,'utime'=>$utime,'content'=>$content);
        $this->_dialy->data($tyData)->add();
        $this->ajaxreturn(1);
	}
	public function addPinglun(){
		$uid=$_SESSION['love_user']['id'];  //模拟session中的用户id
		$utime=time();  //获取当前时间
		// $wid=I();
		$wid=I('wid');
		$content=I('ttconent');
		$cData=array('uid'=>$uid,'wid'=>$wid,'content'=>$content,'utime'=>$utime);
		$this->_comment->data($cData)->add();
		$this->ajaxreturn(1);
	}
}